<template>
  <view class="container">
    <input class="name" type="text" v-model="username" placeholder="用户名/邮箱" />
    <input class="psd" type="password" v-model="pwd" placeholder="密码" />
    <button @click="login">登录</button>
  </view>
</template>
 
<script>
export default {
  data() {
    return {
      username: 'admin',
      pwd: 'abo'
    };
  },
  methods: {
    login() {
      uni.request({
        url: 'api/user/login', // 例如：'https://api.example.com/login'
        method: 'POST',
        data: {
          username: this.username,
          password: this.pwd
        },
        success: (res) => {
          if (res.data) {
            // 登录成功，保存用户信息并跳转页面
            uni.setStorageSync('userInfo', res.data); // 假设后端返回一个token
            uni.navigateTo({ url: '/pages/tabbar/tabbar-5/tabbar-5' }); // 跳转到首页或其他页面
          } else {
            uni.showToast({ title: '登录失败', icon: 'none' });
          }
        },
        fail: () => {
          uni.showToast({ title: '请求失败', icon: 'none' });
        }
      });
    }
  }
}
</script>
<style scoped>
	.container{
		padding: 50% 16rpx;
	}
	.name{
		margin: 20rpx;
		border: 1rpx solid #f3f3f3;
		padding: 6rpx 12rpx;
	}
	.psd{
		margin: 20rpx;
		border: 1rpx solid #f3f3f3;
		padding: 6rpx 12rpx;
	}
</style>